<template>
  <div class="menu">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-button  @click="$router.push({name:'menu-create'})">添加菜单</el-button>
      </div>
      <el-table
      :data="menus"
      style="width: 100%">
        <el-table-column
          label="编号"
          type="index">
        </el-table-column>
        <el-table-column
          prop="name"
          label="菜单名称"
          >
        </el-table-column>
        <el-table-column
          prop="level"
          label="菜单级数">
        </el-table-column>
          <el-table-column
          prop="icon"
          label="前端图标">
        </el-table-column>
          <el-table-column
          prop="orderNum"
          label="排序">
        </el-table-column>
          <el-table-column
          width="180"
          label="操作">
           <template slot-scope="scope">
              <el-button
                size="mini"
                @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
              <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </template>
        </el-table-column>

    </el-table>
    </el-card>
  </div>
</template>

<script lang="ts">
import Vue from 'vue'
import { getAll, menudelete } from '@/services/menu'
export default Vue.extend({
  name: 'MenuIndex',
  data () {
    return {
      menus: []
    }
  },
  created () {
    this.queryMenulist()
  },
  methods: {
    async queryMenulist () {
      const { data } = await getAll()
      this.menus = data
      // console.log(data, '----')
    },
    handleEdit (index: number, row: any) {
      console.log(index, row)
      this.$router.push({ name: 'menu-edite', params: { id: row.id } })
    },
    handleDelete (index: number, row: any) {
      console.log(index, row)
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        await menudelete(row.id)
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
        this.queryMenulist()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
})
</script>

<style lang="scss" scoped></style>
